Is vector<int>::const_iterator an output_iterator?
NickName:xmllmx Ask DateTime:2016-12-01T09:56:24

Is vector<int>::const_iterator an output_iterator?

According to the C++ concepts:

Any iterator other than input_iterator is an output_iterator.

A vector<int>::const_iterator is a random_access_iterator, and of course that is an output_iterator.

However, according to cppreference.com, an output_iterator must be writable, while a vector<int>::const_iterator is not.

Is vector<int>::const_iterator an output_iterator?

See also: How to check if an iterator is an output_iterator in c++?

Copyright Notice:Content Author:「xmllmx」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40901372/is-vectorintconst-iterator-an-output-iterator

Answers
cpplearner 2016-12-01T02:02:54

No. vector<int>::const_iterator is a constant iterator ([container.requirements.general]), which means it does not satisfy the requirements of output iterators. \n\n[iterator.requirements.general]/4:\n\n\n Iterators that further satisfy the requirements of output iterators are called mutable iterators. Nonmutable iterators are referred to as constant iterators.\n\n\n\n\n\n An vector::const_iterator is a random_access_iterator, and of course is an output_iterator.\n\n\nThis is simply wrong.",


Kirill Kobelev 2016-12-01T02:03:40

Look here: Cpp Reference\n\n\n An OutputIterator is an Iterator that can write to the pointed-to\n element.\n",


More about “Is vector<int>::const_iterator an output_iterator?” related questions

Vector of a Vector troubles

Basic Problem Can you please help me understand how to use a vector of a vector. Take for example vector&lt; vector&lt;int&gt; &gt; help. I do not understand if it is a vector of ints who each are a

Show Detail

Find max position in a vector of vector of vector

I have a vector of vector of vector std::vector&lt;std::vector&lt;std::vector&lt;double&gt;&gt;&gt; mountain_table and I would like to find the coordinates i, j, k of this vector for which it is...

Show Detail

Assigning vector of vector of string with vector of string

I want to fill vector of vector of string with different vector of strings.But it is not being filled and same empty values are there which are initialized during definition. int A = 3; vector&lt;...

Show Detail

Define size of vector of vector of vector at the time of declaration

Recently i had a chance to use vector&lt;vector&lt;vector&lt;Some_Struct&gt;&gt;&gt; threeFoldVec, We had to push this into a list. The size threeFoldVec is known at the time of initialization. I am

Show Detail

Copy Vector in a Vector in Java

I'd like to copy a vector to another. The problem is that if I change the vector v1, the second vector v2 is changing too. My goal is to keep the copy intact even if I change the source vector. i...

Show Detail

Appending a New Vector to a Vector

I'm creating a vector that itself will contain a vector, using this code: vector&lt;vector&lt;short&gt;&gt; pixelData; However, I start with an empty vector, and I would like to append a new vect...

Show Detail

Storing a vector of pointers to elements of a vector of vector of ints

If I have say std::vector&lt;std::vector&lt;int&gt;&gt; test_vofv storing a vector of vectors of ints. I now want to store pointers to various elements (by which I mean the outer vector i.e. test_...

Show Detail

vector of vector

I have the following code fragment #include &lt;iostream&gt; #include &lt;ostream&gt; #include &lt;vector&gt; using namespace std; int main() { vector&lt;vector&lt;int&gt;&gt;v;

Show Detail

Initialising vector of vector on the heap

I have a function that takes in the number of rows and columns and initialises a vector of vector with default values of the object 'cell' and return the pointer to that vector. //Cell class clas...

Show Detail

Initializing vector with a vector?

can we iniitialize a vector in c++ with the fuction of returning type vector. #include &lt;sstream&gt; #include &lt;vector&gt; #include &lt;iostream&gt; using namespace std; vector&lt;int

Show Detail